NotEmptyMap

@Serializable(with = NotEmptyMapSerializer::class)
@Since(version = KotoolsTypesVersion.V4_0_0)
value class NotEmptyMap<K, out V>

Represents a map that has at least one entry, with a key of type K and a value of type V.

You can use the notEmptyMapOf or the toNotEmptyMap functions for creating an instance of this type.


Serialization and deserialization

The serialization and deserialization processes of this type behave like for the Map type.

Here's an example of Kotlin code that encodes and decodes this type using the JavaScript Object Notation (JSON) format from kotlinx.serialization:

val map: NotEmptyMap<Char, Int> = notEmptyMapOf('a' to 1, 'b' to 2)
val encoded: String = Json.encodeToString(map)
println(encoded) // {"a":1,"b":2}
val decoded: NotEmptyMap<Char, Int> = Json.decodeFromString(encoded)
println(decoded == map) // true

Types

Link copied to clipboard
object Companion

Contains static declarations for the NotEmptyMap type.

Properties

Link copied to clipboard

All entries of this map.

Link copied to clipboard
val head: Pair<K, V>

The first entry of this map.

Link copied to clipboard

All keys of this map.

Link copied to clipboard

The size of this map.

Link copied to clipboard

All entries of this map except the first one.

Link copied to clipboard

All values of this map.

Functions

Link copied to clipboard
fun toMap(): Map<K, V>

Returns all entries of this map as a Map with keys of type K and values of type V.

Link copied to clipboard
open override fun toString(): String

Returns the string representation of this map.